home *** CD-ROM | disk | FTP | other *** search
- #Additional text which needs to be included during Publish
-
- #AVATAR PROTO FIELDS
- #begin_text
- # version 009
- eventIn SFVec3f destination_point
- eventOut SFTime point_reached
- eventIn SFVec3f set_translation
- eventIn SFRotation set_rotation
- eventOut SFTime animation_finished
- eventOut SFTime animation_started
- #end_text
-
- #MASTERSCRIPT AND MOVERSCRIPT
- #begin_text
- PROTO STUB_SITE [
- exposedField SFNode site NULL
- ]
- { Group {} }
-
- DEF stub_site STUB_SITE {
- site IS _object_site_
- }
-
- DEF MasterScript Script{
- directOutput TRUE
- field SFNode p USE stub_site
- eventIn SFVec3f set_translation
- eventIn SFRotation set_rotation
- eventIn SFTime cycleTime
- eventOut SFVec3f translation_changed
- eventOut SFRotation rotation_changed
- field SFVec3f shift_translation 0 0 0
- field SFRotation shift_rotation 0 0 1 0
- field SFVec3f prev_value_translation 0 0 0
- field SFRotation prev_value_rotation 0 0 1 0
- field SFBool bCycleTimeTranslation TRUE
- field SFBool bCycleTimeRotation TRUE
- field SFBool bChanged FALSE
- field SFBool bChangedShift FALSE
-
- eventIn SFVec3f on_translation IS set_translation
- eventIn SFRotation on_rotation IS set_rotation
-
- url "javascript:
- function initialize(){
- var site = p.site;
- if (site!=null && site.toString()!='0' && site.toString()!='NULL')
- {
- translation_changed = site.translation;
- rotation_changed = site.rotation;
- }
- }
- function getMatrix(tr,rot){
- matr = new VrmlMatrix();
- matr.setTransform ( tr, rot );
- return matr;
- }
- function update(){
- if(bChangedShift)
- {
- curr_matrix = getMatrix(translation_changed,rotation_changed).multLeft(getMatrix(shift_translation,shift_rotation));
- shift_translation = new SFVec3f();
- shift_rotation = new SFRotation();
- bChangedShift=false;
- curr_matrix.getTransform(translation_changed,rotation_changed);
- }
- var site=p.site;
- if (site!=null)
- {
- site.translation = translation_changed;
- site.rotation = rotation_changed;
- }
- }
- function cycleTime(value,timestamp){
- bCycleTimeTranslation = true;
- bCycleTimeRotation = true;
- }
- function on_translation(value,timestamp)
- {
- bChanged = true;
- translation_changed = value;
- }
- function on_rotation(value,timestamp)
- {
- bChanged = true;
- rotation_changed = value;
- }
- function set_translation(value,timestamp)
- {
- bChangedShift = true;
- bChanged = true;
- if (bCycleTimeTranslation)
- {
- prev_value_translation = value;
- bCycleTimeTranslation = false;
- }
- else
- {
- shift_translation = value.subtract(prev_value_translation);
- prev_value_translation = value;
- }
- }
- function set_rotation(value,timestamp)
- {
- bChangedShift = true;
- bChanged = true;
- if (bCycleTimeRotation)
- {
- prev_value_rotation = value;
- bCycleTimeRotation = false;
- }
- else
- {
- value_matrix = getMatrix(new SFVec3f(),value);
- prev_value_matrix = getMatrix(new SFVec3f(),prev_value_rotation);
- shift_matrix = prev_value_matrix.inverse().multLeft(value_matrix);
- shift_matrix.getTransform(new SFVec3f(),shift_rotation);
-
- prev_value_rotation = value;
- }
- }
- function eventsProcessed()
- {
- if (bChanged)
- {
- update();
- bChanged = false;
- }
- }
- "
- }
-
- DEF MoveScript Script
- {
- url "javascript:
- function initialize()
- {
- Browser.addRoute(timer,'time',self,'animate');
- }
- function set_distance(value)
- {
- anim_dist = value;
- }
- function set_animTimer(value)
- {
- if (!timer.enabled || bMove)
- anim_timer = value;
- }
-
- function atan2(y,x)
- {
- if (x==0)
- {
- if (y==0) return 0;
- else return (y>0) ? Math.PI : -Math.PI;
- }
- else
- {
- r = Math.atan(y/x);
- if (x<0) r = r + ((y>0) ? Math.PI : -Math.PI);
- return r;
- }
- }
-
- function getAzimuth( center, to )
- {
- diff = to.subtract(center);
- return Math.atan2(diff.x, diff.z);
- }
-
-
- function animate(value)
- {
- pos = getPos();
- diff = target.subtract(pos);
- diff.y=0;
- dist = diff.length();
- if (dist>0.001)
- {
- shift = pos.subtract(prev_pos).length();
- pos.y = pos.y + (target.y - pos.y) * shift / dist;
- }
- if( isNaN(prev_time) || prev_time == 0 )
- prev_time = prev_time;
- dur = value - prev_time;
- if (bMove)
- {
- if((target.y-pos.y)!=0)
- MasterScript.on_translation = pos;
- if (dist<anim_dist/2)
- stopIt(value);
- else
- rotate(pos,dur);
- }
- else
- {
- startTime = anim_timer.startTime;
- stopTime = timerStopTime;
- timeTime = value;
- if (startTime<stopTime)
- {
- if (timeTime>=stopTime)
- {
- timer.enabled = false;
- bStopInProgress = false;
- MasterScript.on_translation = target;
- }
- else
- {
- coeff = (timeTime-stopped)/(stopTime-stopped);
- if (coeff>1) coeff = 1;
- diff = diff.multiply(coeff);
- MasterScript.on_translation = pos.add(diff);
- }
- }
- }
- prev_time = value;
- prev_pos = pos;
- }
-
- function stopIt(value)
- {
-
- bStopInProgress = true;
- timerStopTime = anim_timer.cycleTime + anim_timer.cycleInterval;
- stopped = value;
- print('stop It '+value);
- }
-
- function stop(value)
- {
- if (bMove)
- {
- bMove = false;
- bUseTarget = false;
- }
- }
-
- function getPos()
- {
- return new SFVec3f(MasterScript.translation_changed.x,MasterScript.translation_changed.y,MasterScript.translation_changed.z);
- }
-
- function pointToMove(value)
- {
- bUseTarget = true;
- point = value;
- if (bMove)
- target = point;
- }
-
- function start(value)
- {
- if (value>0)
- started = true;
- }
- function startIt(value)
- {
- bStopInProgress = false;
- if (!bMove)
- {
- bMove = true;
- timer.enabled = true;
- prev_time = value;
- prev_pos = getPos();
- started = value;
- bCalculateAnimDist = true;
- anim_cycle = 0;
- }
- if (bMove)
- target = point;
- }
-
- function getOri()
- {
- rot = MasterScript.rotation_changed;
- return ((rot.y>0)?1:-1)*rot.angle;
- }
-
- function normRot(f)
- {
- PIm2 = Math.PI*2;
- while (f > Math.PI)
- f = f-PIm2;
- while (f < -Math.PI)
- f = f+PIm2;
- return f;
- }
-
- function setRotation(rot)
- {
- MasterScript.on_rotation = new SFRotation(0,1,0,rot);
- }
-
- function rotate(pos,dur)
- {
- m_angSpeed = 3;
- angle60 = Math.PI/3;
-
- azim = getAzimuth(pos,target);
- ori = getOri();
- angle = azim - ori;
- angle = normRot( angle );
- absAngle = Math.abs(angle);
-
- canRotate = dur * m_angSpeed;
- if( absAngle >= canRotate )
- {
- a = (angle>0)?canRotate:-canRotate;
- if( absAngle >= angle60 )
- a = a * (1 + absAngle - angle60);
- setRotation(a+ori);
- }
- else if( absAngle >= 0.001 )
- {
- setRotation(azim);
- }
- }
- function eventsProcessed()
- {
- if (started && bUseTarget)
- startIt();
- if (started)
- started = false;
- }
- "
- directOutput TRUE
- field SFNode MasterScript USE MasterScript
- field SFNode timer TimeSensor
- {
- enabled FALSE
- loop TRUE
- }
- field SFNode self USE MoveScript
- eventIn SFTime start
- eventIn SFTime stop
- eventIn SFVec3f pointToMove IS destination_point
- eventOut SFTime stopped IS point_reached
- eventIn SFFloat set_distance
- eventIn SFTime animate
- eventIn SFNode set_animTimer
- field SFNode anim_timer NULL
- field SFBool bUseTarget FALSE
- field SFBool bMove FALSE
- field SFVec3f point 0 0 0
- field SFVec3f target 0 0 0
- field SFVec3f prev_pos 0 0 0
- field SFTime prev_time 0
- field SFFloat anim_dist 0
- field SFTime anim_cycle 0
- field SFTime timerStopTime 0
- field SFBool bCalculateAnimDist FALSE
- field SFBool bStopInProgress FALSE
- field SFBool started FALSE
- }
- #end_text
-
- #ANIMATION ENGINE PROTO
- #begin_text
- PROTO AnimationEngine [
- exposedField SFTime cycleInterval 1
- exposedField SFBool enabled TRUE
- exposedField SFBool loop TRUE
- eventIn SFTime startTime
- eventIn SFTime stopTime
- eventOut SFTime cycleTime
- eventOut SFFloat fraction_changed
- eventOut SFBool isActive
- eventOut SFTime time
- eventOut SFTime animation_finished
- eventOut SFTime animation_started
-
- eventIn SFTime realStartTime
- eventOut SFTime realStopTime
- eventOut SFTime stopOthers
-
- field SFNode animationNode NULL
-
- field SFNode moveScript NULL
-
- field SFBool debug FALSE
- ]
- {
- DEF AnimationTimer TimeSensor {
- cycleInterval IS cycleInterval
- enabled IS enabled
- loop IS loop
- cycleTime IS cycleTime
- isActive IS isActive
- time IS time
- startTime -1
- }
- DEF AnimationScript Script {
- directOutput TRUE
- field SFNode timer_node USE AnimationTimer
- field SFNode animation_node IS animationNode
-
- field SFBool play FALSE
- field SFFloat fraction_tmp 1
-
- eventIn SFTime set_startTime IS startTime
- eventIn SFTime set_stopTime IS stopTime
- eventIn SFFloat set_fraction
-
- eventIn SFTime realStartTime IS realStartTime
- eventOut SFTime realStopTime IS realStopTime
-
- eventIn SFBool isActive
- eventOut SFTime animation_finished IS animation_finished
- eventOut SFTime animation_started IS animation_started
-
- eventOut SFTime stopOthers IS stopOthers
-
- field SFNode moveScript IS moveScript
- field SFBool locomotive FALSE
- field SFFloat distance 0
-
- field SFBool finished FALSE
- field SFBool debug IS debug
- field SFBool activated FALSE
- field SFBool loop FALSE
-
- url "javascript:
- function getDistance(node){
- if (node!=null)
- {
- for(i=0;i<node.connectTo.length;i++)
- if (node.connectTo[i]=='MASTER.translation')
- {
- ip = node.interpolators[i];
- v1 = ip.keyValue[0];
- v2 = ip.keyValue[ip.keyValue.length-1];
- return v1.subtract(v2).length();
- }
- }
- return 0;
- }
- function initialize(){
- distance = getDistance(animation_node);
- locomotive = distance>0.1;
- activated = false;
- loop = timer_node.loop;
- }
-
- function isActive(value,timestamp){
- activated = value;
- if(value)
- {
- animation_started = timestamp;
- timer_node.loop = loop;
- }
- else if(play)
- {
- play = false;
- animation_finished = timestamp;
- finished = true;
- }
- }
- function realStartTime(value){
- if (play)
- {
- timer_node.loop = true;
- timer_node.startTime = value;
- timer_node.stopTime = 0;
- if (moveScript!=null){
- moveScript.set_animTimer = timer_node;
- if (locomotive)
- {
- moveScript.start = value;
- moveScript.set_distance = distance;
- }
- else
- moveScript.stop = value;
- }
- }
- }
- function set_startTime(value){
- if (play || value<0) return;
- play = true;
- stopOthers = value;
- if (finished)
- {
- finished = false;
- realStartTime(value);
- }
- }
- function set_stopTime(value){
- if (!play)
- {
- if (finished)
- {
- finished = false;
- realStopTime = value;
- }
- return;
- }
- play = false;
- if (timer_node.startTime>value)
- {
- realStopTime = timer_node.startTime;
- timer_node.startTime = -1;
- }
- else
- {
- if( timer_node.cycleTime > 0 )
- timer_node.stopTime = timer_node.cycleTime+timer_node.cycleInterval;
- else
- timer_node.stopTime = timer_node.startTime+timer_node.cycleInterval;
- realStopTime = timer_node.stopTime;
- }
- if (moveScript!= null && locomotive)
- moveScript.stop = value;
- }
- function set_fraction(value){
- if (play == false && fraction_tmp > value)
- fraction_tmp = 1;
- else
- fraction_tmp = value;
- if (debug) print(animation_node+':'+value);
- }
- function eventsProcessed(){
- if (activated)
- animation_node.fractionShift = fraction_tmp;
- }"
- }
- ROUTE AnimationTimer.fraction_changed TO AnimationScript.set_fraction
- ROUTE AnimationTimer.isActive TO AnimationScript.isActive
- }
-
- PROTO SequenceEngine [
- exposedField SFTime cycleInterval 1
- exposedField SFBool enabled TRUE
- exposedField SFBool loop TRUE
- eventIn SFTime startTime
- eventIn SFTime stopTime
- eventOut SFTime cycleTime
- eventOut SFFloat fraction_changed
- eventOut SFBool isActive
- eventOut SFTime time
- eventOut SFTime animation_finished
- eventOut SFTime animation_started
-
- eventIn SFTime realStartTime
- eventOut SFTime realStopTime
- eventOut SFTime stopOthers
-
- field SFNode animationNode NULL
-
- field SFNode moveScript NULL
- ]
- {
-
- DEF SequenceTimer TimeSensor {
- cycleInterval IS cycleInterval
- enabled IS enabled
- loop IS loop
- isActive IS isActive
- time IS time
- startTime -1
- }
- DEF SequenceScript Script {
- directOutput TRUE
- field SFNode timer_node USE SequenceTimer
- field SFNode animation_node NULL
- field SFNode sequence_node IS animationNode
-
- field SFBool play FALSE
- field SFFloat fraction_tmp 1
- field SFTime start_time 0
- field SFTime cycle 1
- field SFInt32 anim_cnt 1
- field SFInt32 anim_num 1
-
- eventOut SFTime cycleTime IS cycleTime
- eventIn SFTime set_startTime IS startTime
- eventIn SFTime set_stopTime IS stopTime
- eventIn SFTime set_time
-
- eventIn SFTime realStartTime IS realStartTime
- eventOut SFTime realStopTime IS realStopTime
-
- eventIn SFBool isActive
- eventOut SFTime animation_finished IS animation_finished
- eventOut SFTime animation_started IS animation_started
-
- eventOut SFTime stopOthers IS stopOthers
-
- field SFNode moveScript IS moveScript
- field SFBool locomotive FALSE
- field SFBool bStartDoEnd FALSE
- field SFBool finished FALSE
- field MFFloat distance []
- field SFBool activated FALSE
- field SFBool loop FALSE
-
- url "vrmlscript:
-
- function getDistance(node){
- if (node!=null)
- {
- var i;
- for(i=0;i<node.connectTo.length;i++)
- if (node.connectTo[i]=='MASTER.translation')
- {
- var ip;
- var v1;
- var v2;
- ip = node.interpolators[i];
- v1 = ip.keyValue[0];
- v2 = ip.keyValue[ip.keyValue.length-1];
- return v1.subtract(v2).length();
- }
- }
- return 0;
- }
- function initialize()
- {
- anim_cnt = sequence_node.sequence.length;
- var i;
- for(i=0;i<anim_cnt;i++)
- {
- dist = getDistance(sequence_node.children[sequence_node.sequence[i]]);
- distance[i] = dist;
- locomotive = (locomotive) || (dist>0.1);
- }
- bStartDoEnd = sequence_node.start_do_end;
- loop = timer_node.loop;
- }
- function isActive(value,timestamp){
- activated = value;
- if(value)
- {
- animation_started = timestamp;
- timer_node.loop = loop;
- }
- else if(play)
- {
- play = false;
- animation_finished = timestamp;
- finished = true;
- }
- }
- function realStartTime(value){
- if (play)
- {
- anim_num = 0;
- anim_cnt = sequence_node.sequence.length;
- animation_node = sequence_node.children[sequence_node.sequence[anim_num]];
- cycle = 1/animation_node.pitch;
- start_time = value;
- timer_node.loop = true;
- timer_node.startTime = value;
- timer_node.stopTime = 0;
- if (moveScript!=null){
- moveScript.set_animTimer = timer_node;
- if (locomotive)
- {
- moveScript.start = value;
- moveScript.set_distance = distance[anim_num];
- }
- else
- moveScript.stop = value;
- }
- }
- }
- function set_startTime(value){
- if (play || value<0) return;
- play = true;
- stopOthers = value;
- if (finished)
- {
- finished = false;
- realStartTime(value);
- }
- }
- function set_stopTime(value){
- if (!play)
- {
- if (finished)
- {
- finished = false;
- realStopTime = value;
- }
- return;
- }
- play = false;
- if (timer_node.startTime>value)
- {
- realStopTime = timer_node.startTime;
- timer_node.startTime = -1;
- }
- else
- {
- var timerStopTime = start_time+cycle;
- var i;
- if (bStartDoEnd)
- for (i=anim_num+1;i<anim_cnt;i++)
- {
- var node = sequence_node.children[sequence_node.sequence[i]];
- var c = 1/node.pitch;
- timerStopTime = timerStopTime + c;
- }
- timer_node.stopTime = timerStopTime;
- realStopTime = timerStopTime;
- }
- if (moveScript!= null && locomotive)
- moveScript.stop = value;
- }
- function set_time(value){
- fraction_tmp = (value-start_time)/cycle;
- if (fraction_tmp > 1){
- start_time = value;
- anim_num = anim_num + 1;
- if (anim_num >= anim_cnt-1 && bStartDoEnd && play) anim_num = 1;
- animation_node = sequence_node.children[sequence_node.sequence[anim_num]];
- cycle = 1/animation_node.pitch;
- timer_node.cycleInterval = cycle;
- fraction_tmp = (value-start_time)/cycle;
- cycleTime = start_time;
- if (moveScript!=null && locomotive)
- moveScript.set_distance = distance[anim_num];
- if (anim_num >= anim_cnt-1 && !bStartDoEnd)
- timer_node.stopTime = start_time+cycle;
- }
- }
- function eventsProcessed(){
- if (activated)
- animation_node.fractionShift = fraction_tmp;
- }"
- }
- ROUTE SequenceTimer.time TO SequenceScript.set_time
- ROUTE SequenceTimer.isActive TO SequenceScript.isActive
- }
- #end_text
-